﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Clock
{
    public delegate void TickHandler(object sender, EventArgs args);
    public delegate void AlarmHandler(object sender,EventArgs args);
    public class MyClock
    {
        public DateTime time { get; set; }
        public DateTime alarmTime { get; set; }
        public bool isOpen = false;
        public MyClock() {
            time = DateTime.Now;
        }

        public MyClock(DateTime alarmTime)
        {
            time = DateTime.Now;
            this.alarmTime = alarmTime;
        }
        
        public event TickHandler OnTick;
        public event AlarmHandler OnAlarm;

        public void Open()
        {
            isOpen = true;
            while (isOpen)
            {
                EventArgs args1 = new EventArgs()
                {
                    time = this.time
                };
                EventArgs args2 = new EventArgs()
                {
                    time = alarmTime
                };
                OnTick(this,args1);
                OnAlarm(this,args2);
                time=time.AddSeconds(1);
                System.Threading.Thread.Sleep(1000);
            }
        }
    }
}
